/* -*- Mode: c; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/*
  RefObject (http://code.google.com/p/refobject/)
  Copyright (C) 2010-2011 MIURA Shirow (sharow)
*/

#include <stdio.h>
#include <stdlib.h>
#include <RefObject/RefAllocator.h>
#include <RefObject/RefByteArray.h>
#include <RefObject/RefModule.h>

static unsigned char stgByteArray[] = {0, 1, 2, 3};

int
main(void)
{
    RefObject *byte_array;
    if (RefModule_Initialize(RefAllocatorForModule_CreateFromStdCMallocFree(malloc, free))) {
        printf("Initialize fail\n");
        return 1;
    }

    byte_array = RefByteArray_CreateDuplicate(stgByteArray, sizeof(stgByteArray));
    if (!byte_array) {
        printf("RefByteArray_CreateShallow fail\n");
        return 1;
    }
    printf("RefByteArray_IsValid: %d\n", RefByteArray_IsValid(byte_array));
    printf("RefByteArray_AsByteArray: %d\n", RefByteArray_AsByteArray(byte_array)[0]);
    printf("RefByteArray_AsByteArray: %d\n", RefByteArray_AsByteArray(byte_array)[1]);
    RefObject_DecRef(byte_array);
    byte_array = NULL;

    RefModule_Finalize();
    printf("Exit success\n");
    return 0;
}
